home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form Form1
- Caption = "Form1"
- ClientHeight = 3885
- ClientLeft = 1875
- ClientTop = 1680
- ClientWidth = 4800
- Height = 4290
- Left = 1815
- LinkMode = 1 'Source
- LinkTopic = "Form1"
- ScaleHeight = 3885
- ScaleWidth = 4800
- Top = 1335
- Width = 4920
- Begin VScrollBar VScroll1
- Height = 2430
- LargeChange = 9
- Left = 4395
- Max = 5000
- Min = 1
- TabIndex = 5
- Top = 1305
- Value = 5000
- Width = 300
- End
- Begin Grid Grid1
- Cols = 3
- FixedCols = 0
- FixedRows = 0
- Height = 2430
- Left = 105
- Rows = 10
- TabIndex = 6
- Top = 1305
- Width = 4290
- End
- Begin TextBox T_Input
- Height = 375
- Left = 120
- TabIndex = 0
- Text = "4321.99"
- Top = 840
- Width = 1200
- End
- Begin CommandButton B_Quit
- Caption = "&Quit"
- Height = 495
- Left = 3855
- TabIndex = 4
- Top = 750
- Width = 840
- End
- Begin PictureBox Picture1
- BorderStyle = 0 'None
- Height = 570
- Left = 4095
- Picture = HUGEGRID.FRX:0000
- ScaleHeight = 570
- ScaleWidth = 555
- TabIndex = 7
- Top = 105
- Width = 555
- End
- Begin CommandButton B_Del
- Caption = "&Delete"
- Height = 495
- Left = 3000
- TabIndex = 9
- Top = 120
- Width = 825
- End
- Begin CommandButton B_Insert
- Caption = "&Insert"
- Height = 510
- Left = 2040
- TabIndex = 3
- Top = 105
- Width = 840
- End
- Begin CommandButton B_Find
- Caption = "&Find"
- Height = 495
- Left = 1080
- TabIndex = 2
- Top = 120
- Width = 840
- End
- Begin CommandButton B_Sort
- Caption = "&Sort"
- Height = 495
- Left = 120
- TabIndex = 1
- Top = 120
- Width = 840
- End
- Begin Label Label1
- Caption = "Enter a number to search column 1 for or to insert. "
- Height = 405
- Left = 1425
- TabIndex = 8
- Top = 825
- Width = 2280
- End
- Dim Entry As Element
- Dim pointer&(6000)
- 'Rather than move elements around in an array (or on disk, if you use these
- 'routines with a random access file instead), we use pointers to the records
- 'instead.
- Dim Deleted&(6000), NumDeleted
- 'Again, rather than move data around when when an element is deleted,
- 'we keep track of deleted elements and reuse them when adding new elements.
- 'Of course, when saving to disk, you would ignore the deleted elements.
- Dim GridStart 'pointer number of the first element on the grid
- Dim CurEl 'pointer number of the last element found on a search
- Dim LastElement 'number of elements in the Array - 5000, in this example
- Dim ArraySorted 'flag to show if the Huge Array is sorted.
- Dim PgAmt 'number of lines to page up and down by
- Dim Bottom(10), Topp(10) 'variables used in the sort routine.
- Dim LastValue 'last value selected on scroll bar
- Dim IgnoreChange 'flag to allow changing Vscroll1.value without executing
- 'Vscroll1.Change
- Dim MatchRow 'Grid row number where matching item is after a Find
- 'Copyright 1991 Nelson Ford, Public (software) Library
- Sub B_Del_Click ()
- If Grid1.CellSelected = 0 Then
- If Grid1.SelStartRow = Grid1.SelEndRow And Grid1.SelStartCol = Grid1.SelEndCol Then
- Grid1.Row = Grid1.SelStartRow
- Grid1.Col = Grid1.SelStartCol
- Else
- MsgBox "Cell not selected."
- Exit Sub
- End If
- End If
- r = GridStart + Grid1.Row 'array element number
- x = MsgBox("Delete entire row?", 3)
- If x = 2 Then
- Exit Sub
- ElseIf x = 7 Then 'just delete cell, not the entire entry
- Grid1.Text = ""
- Grid1.Col = 0: Entry.a1 = Grid1.Text
- Grid1.Col = 1: Entry.a2 = Grid1.Text
- Grid1.Col = 2: Entry.a3 = Grid1.Text
- e = SetHugeEl(hArray, pointer&(r), Entry)
- If e < 0 Then MsgBox "Error deleting data."
- Else
- NumDeleted = NumDeleted + 1
- Deleted&(NumDeleted) = pointer&(r)
- For i = r To LastElement
- pointer&(i) = pointer&(i + 1)
- Next
- Call DecrLastEl
- rw = Grid1.Row
- If GridStart + 9 < LastElement Then
- Call ScrollUp(rw, 8)
- Call FillGrid(GridStart + 9, GridStart + 9, 9)
- Else
- GridStart = GridStart - 1
- Call ScrollDown(1, rw)
- Call FillGrid(GridStart, GridStart, 0)
- End If
- End If
- T_Input.SetFocus
- 'Copyright 1991 Nelson Ford, Public (software) Library
- End Sub
- Sub B_Find_Click ()
- If T_Input.Text = "" Then
- MsgBox "Nothing entered."
- Exit Sub
- End If
- u = LastElement
- l = 1
- If u < l Then Exit Do
- i = (l + u) / 2
- x = GetHugeEl(hArray, pointer&(i), Entry): If x < 0 Then Stop
- 'Debug.Print l; u, T_Input.Text, Entry.a1
- If T_Input.Text = RTrim$(LTrim$(Entry.a1)) Then
- Exit Do
- ElseIf T_Input.Text > RTrim$(LTrim$(Entry.a1)) Then
- l = i + 1
- Else
- u = i - 1
- End If
- Loop
- CurEl = i
- StartPt = i - 1
- If StartPt < 1 Then
- StartPt = 1
- MatchRow = 0
- ElseIf StartPt > LastElement - 9 Then
- StartPt = LastElement - 9
- MatchRow = LastElement - StartPt
- Else
- MatchRow = 1
- End If
- IgnoreChange = -1
- If StartPt + 9 >= LastElement Then
- Vscroll1.Value = LastElement
- ElseIf StartPt = 1 Then
- Vscroll1.Value = 1
- Else
- Vscroll1.Value = StartPt
- End If
- IgnoreChange = 0
- LastValue = Vscroll1.Value
- Call FillGrid(StartPt, StartPt + 9, 0)
- GridStart = StartPt
- Grid1.Row = MatchRow
- Grid1.SelStartRow = MatchRow
- Grid1.SelEndRow = MatchRow
- Grid1.SelStartCol = 0
- Grid1.SelEndCol = 0
- T_Input.SetFocus
- End Sub
- Sub B_Insert_Click ()
- If LastElement = ArraySize Then
- MsgBox "Out of room."
- Exit Sub
- ElseIf T_Input.Text = "" Then
- MsgBox "Enter something in the Text Box."
- Exit Sub
- End If
- Call B_Find_Click
- Grid1.Row = MatchRow
- Grid1.Col = 0
- 'If a match was not found, the contents of Grid.Row=MatchRow, .Col=0
- ' will be the closest match value.
- 'Test to see if the new value is < or => the contents of that cell:
- If MatchRow < 5 Then
- If T_Input.Text < RTrim$(LTrim$(Grid1.Text)) Then
- Call ScrollDown(MatchRow + 1, 9)
- Grid1.Row = MatchRow
- CurEl = GridStart + MatchRow
- Else
- Call ScrollDown(MatchRow + 2, 9)
- Grid1.Row = MatchRow + 1
- CurEl = GridStart + MatchRow + 1
- End If
- Else
- If T_Input.Text < RTrim$(LTrim$(Grid1.Text)) Then
- Call ScrollUp(0, MatchRow - 2)
- Grid1.Row = MatchRow - 1
- CurEl = GridStart + MatchRow
- Else
- Call ScrollUp(0, MatchRow - 1)
- Grid1.Row = MatchRow
- CurEl = GridStart + MatchRow + 1
- End If
- End If
- Grid1.Col = 0
- Entry.a1 = T_Input.Text
- Grid1.Text = T_Input.Text
- Grid1.Col = 1
- Entry.a2 = ""
- Grid1.Text = ""
- Grid1.Col = 2
- Entry.a3 = ""
- Grid1.Text = ""
- Call IncrLastEl
- If MatchRow > 5 Then GridStart = GridStart + 1
- For i = LastElement To CurEl + 1 Step -1
- pointer&(i) = pointer&(i - 1)
- Next
- If NumDeleted > 0 Then
- pointer&(CurEl) = Deleted&(NumDeleted)
- NumDeleted = NumDeleted - 1
- Else
- pointer&(CurEl) = LastElement
- End If
- e = SetHugeEl(hArray, pointer&(CurEl), Entry)
- If e < 0 Then MsgBox "Error in inserting data.": Stop
- T_Input.SetFocus
- End Sub
- Sub B_Quit_Click ()
- i = HugeErase(hArray)
- End
- End Sub
- Sub B_Sort_Click ()
- MousePointer = 11
- Ply = 1
- Bottom(1) = 1
- Topp(1) = LastElement
- While Ply > 0
- If Bottom(Ply) >= Topp(Ply) Then
- Ply = Ply - 1
- Else
- i = Bottom(Ply) - 1
- j = Topp(Ply)
- Pt$ = GetEl$(j)
- While i < j
- i = i + 1
- j = j - 1
- While GetEl$(i) < Pt$
- i = i + 1
- Wend
- While GetEl$(j) > Pt$ And j > i
- j = j - 1
- Wend
- If i < j Then
- x = pointer&(i)
- pointer&(i) = pointer&(j)
- pointer&(j) = x
- End If
- Wend
- j = Topp(Ply)
- ii$ = GetEl$(i)
- If i <> j And ii$ > GetEl$(j) Then
- x = pointer&(i)
- pointer&(i) = pointer&(j)
- pointer&(j) = x
- End If
- If i - Bottom(Ply) < Topp(Ply) - i Then
- Bottom(Ply + 1) = Bottom(Ply)
- Topp(Ply + 1) = i - 1
- Bottom(Ply) = i + 1
- Else
- Topp(Ply + 1) = Topp(Ply)
- Bottom(Ply + 1) = i + 1
- Topp(Ply) = i - 1
- End If
- Ply = Ply + 1
- End If
- Wend
- MousePointer = 0
- ArraySorted = -1
- Call FillGrid(1, 10, 0): IgnoreChange = -1
- Vscroll1.Value = 10: IgnoreChange = 0
- End Sub
- Sub DecrLastEl ()
- 'takes care of all the ramifications of decreasing LastElement
- LastElement = LastElement - 1
- IgnoreChange = -1
- Vscroll1.Max = LastElement
- IgnoreChange = 0
- If LastValue > LastElement Then LastValue = LastElement
- End Sub
- Sub FillGrid (StartPt, StopPt, StartRow)
- For i = StartPt To StopPt
- x = GetHugeEl(hArray, pointer&(i), Entry)
- If x > 0 Then Stop
- Grid1.Row = i - StartPt + StartRow
- Grid1.Col = 0
- Grid1.Text = Entry.a1
- Grid1.Col = 1
- Grid1.Text = Entry.a2
- Grid1.Col = 2
- Grid1.Text = Entry.a3
- Next
- End Sub
- Sub Form_Load ()
- Form1.Show
- MousePointer = 11
- ArraySize = 6000
- LastElement = 5000 'amount of data we are going to stuff into the array
- SortedArray = 0
- 'Set width of each grid column:
- Grid1.Col = 0: Grid1.Colwidth = 1200
- Grid1.Col = 1: Grid1.Colwidth = 1400
- Grid1.Col = 2: Grid1.Colwidth = 1600
- 'Set up Scroll bar values:
- Vscroll1.Max = LastElement
- Vscroll1.Min = 1
- Vscroll1.LargeChange = Grid1.Rows - 1
- Vscroll1.SmallChange = 1: IgnoreChange = -1
- Vscroll1.Value = LastElement: IgnoreChange = 0
- LastValue = LastElement
- 'Set up HugeArray (requires Hugearr.dll in PATH)
- hArray = HugeDim(Len(Entry), ArraySize)
- If hArray < 0 Then
- MsgBox "Error dimensioning array: " + Str$(hArray)
- Stop
- End If
- 'fill array with dummy data
- For i = 1 To LastElement
- Entry.a1 = Mid$(Str$(i + .1), 2)
- Entry.a2 = Mid$(Str$(i + .2), 2)
- Entry.a3 = Mid$(Str$(i + .3), 2)
- pointer&(i) = i
- x = SetHugeEl(hArray, pointer&(i), Entry)
- If x > 0 Then Stop
- Next
- 'display last 10 entries in the Grid:
- GridStart = LastElement - 9
- Call FillGrid(GridStart, LastElement, 0)
- Grid1.Row = 0
- Grid1.Col = 0
- Grid1.SelStartRow = 0
- Grid1.SelStartCol = 0
- T_Input.SetFocus
- MousePointer = 0
- End Sub
- Function GetEl (x) As String
- e = GetHugeEl(hArray, pointer&(x), Entry): If e < 0 Then Stop
- GetEl$ = Entry.a1
- End Function
- Sub IncrLastEl ()
- 'takes care of all the ramifications of increasing LastElement
- LastElement = LastElement + 1
- IgnoreChange = -1
- Vscroll1.Max = LastElement
- If Vscroll1.Value > Vscroll1.Max - 10 Then
- Vscroll1.Value = Vscroll1.Max
- LastValue = Vscroll1.Value
- End If
- IgnoreChange = 0
- End Sub
- Sub Picture1_Click ()
- m$ = "Public (software) Library is the most extensive collection of pd/shareware available. "
- m$ = m$ + "We have a large collection of routines for all languages, including VB. "
- m$ = m$ + "For a catalog, call 800-242-4PsL or write PsL, P.O.Box 35705, Houston, TX 77235-5705."
- MsgBox m$
- End Sub
- Sub ScrollDown (StartRow, StopRow)
- For i = StopRow To StartRow Step -1
- Grid1.Row = i - 1
- Grid1.Col = 0
- x0$ = Grid1.Text
- Grid1.Col = 1
- x1$ = Grid1.Text
- Grid1.Col = 2
- x2$ = Grid1.Text
- Grid1.Row = i
- Grid1.Col = 0
- Grid1.Text = x0$
- Grid1.Col = 1
- Grid1.Text = x1$
- Grid1.Col = 2
- Grid1.Text = x2$
- Next
- End Sub
- Sub ScrollUp (StartRow, StopRow)
- For i = StartRow To StopRow
- Grid1.Row = i + 1
- Grid1.Col = 0
- x0$ = Grid1.Text
- Grid1.Col = 1
- x1$ = Grid1.Text
- Grid1.Col = 2
- x2$ = Grid1.Text
- Grid1.Row = i
- Grid1.Col = 0
- Grid1.Text = x0$
- Grid1.Col = 1
- Grid1.Text = x1$
- Grid1.Col = 2
- Grid1.Text = x2$
- Next
- End Sub
- Sub T_Input_GotFocus ()
- T_Input.SelStart = 0
- T_Input.SelLength = 32767
- End Sub
- Sub Vscroll1_Change () 'See "Change Property" in the VB Manual.
- 'Stop
- If IgnoreChange Then Exit Sub
- If Vscroll1.Value = LastValue - 1 Then 'up arrow clicked: scroll down
- GridStart = GridStart - 1
- Call ScrollDown(1, 9)
- Call FillGrid(GridStart, GridStart, 0)
- ElseIf Vscroll1.Value = LastValue + 1 Then 'down arrow clicked: scroll up
- GridStart = GridStart + 1
- Call ScrollUp(0, 8)
- Call FillGrid(GridStart + 9, GridStart + 9, 9)
- Else
- If Vscroll1.Value = LastValue - 9 Then 'clicked above handle: page down
- GridStart = GridStart - 9
- ElseIf Vscroll1.Value = LastValue + 9 Then 'clicked below handle: page up
- GridStart = GridStart + 9
- Else 'moved handle
- GridStart = Vscroll1.Value
- If GridStart > LastElement - 9 Then GridStart = LastElement - 9
- End If
- Call FillGrid(GridStart, GridStart + 9, 0)
- End If
- LastValue = Vscroll1.Value
- End Sub
-